package com.project.frba.bi.transformation;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.project.frba.bi.descriptor.Dimension;

public class FactTableRow implements Row{
	
	private Long id = 0L;
	//TODO es long, ver validacion de tipos
	private Long metric;
	private Map<String, Long> dimensions = new HashMap<String, Long>();
	private FactTable factTable;
	
	public FactTableRow(FactTable factTable) {
		this.factTable = factTable;
	}

	public FactTable getFactTable() {
		return factTable;
	}

	public void setFactTable(FactTable factTable) {
		this.factTable = factTable;
	}

	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}

	public void addField(String dimensionName, Long id) {
		this.dimensions.put(dimensionName, id);
		
	}
	
	public <T> T getMetric(Class<T> metricType){
		return metricType.cast(this.getMetric());
	}

	public Long getMetric() {
		return metric;
	}

	public void setMetric(Long metric) {
		this.metric = metric;
	}
	
	
	public String getInsertValueStatement(){
		Collection<Dimension> dimensions = this.getFactTable().getDescriptor().getDimensions();
		StringBuffer value = new StringBuffer();
		value.append("(");
		value.append(this.id + ",");
		value.append(this.metric);
		for (Dimension dimension : dimensions) {
			value.append("," + this.dimensions.get(dimension.getName()));			
		}
		value.append(")");
		return value.toString();
	}
	
	
	

}
